//
//  SQLiteFsRepository.h
//  FuseSQLite
//
//  Created by Admin on 7/20/14.
//  Copyright (c) 2014 Admin. All rights reserved.
//

#ifndef SQLITE_FS_REPOSITORY_H_
#define SQLITE_FS_REPOSITORY_H_

#include "FsRepository.h"

#include <sqlite3.h>

#include <memory>
#include <vector>
#include <string>

struct HardLink
{
    enum Type
    {
        kFolder,
        kFile,
        kSymLink
    };
    
    std::string name;
    int id;

    Type nodeType;
    int nodeId;
    int attributes;
    int parentId;
};

class SQLiteFsRepository : public FsRepository
{
public:
    SQLiteFsRepository(const char* dbPath);
    virtual ~SQLiteFsRepository();
    
    virtual bool doesHardLinksTableExisits();
    virtual bool doesFoldersTableExists();
    virtual void createHardLinksTable();
    virtual void createFoldersTable();
    virtual int addFolder();
    virtual int addFolderLink(const char* name, int folderId, int attributes, int parentFolderId);
    virtual HardLink getHardLinkInfo(int linkId);
    
    int getFoldersCount();
    std::vector<HardLink> getHardLinks();
    
private:
    bool doesTableExist(const char* tableName);
    std::shared_ptr<sqlite3_stmt> executeQuery(const char* queryStr);
    
private:
    sqlite3* m_db;
};

#endif //SQLITE_FS_REPOSITORY_H_
